import React from 'react'
import PropTypes from 'prop-types'
import { routerRedux } from 'dva/router'
import { connect } from 'dva'
import { Row, Col, Button, Popconfirm,Card } from 'antd'
import List from './List'
import Filter from './Filter'
import Modal from './Modal'
import { Tabs } from 'antd'
import { TextMessage } from './components'
import { color } from '../../utils'
const Mock = require('mockjs')

debugger
const bodyStyle = {
  bodyStyle: {
    height: 432,
    background: '#fff',
  },
}

const Realmessage = ({ location, dispatch, realmessage, loading }) => {
  const { list, pagination, currentItem, modalVisible, modalType, isMotion, selectedRowKeys } = realmessage
  const { pageSize } = pagination
  const { query = {}, pathname } = location

  const listProps = {
    dataSource: list,
    loading: loading.effects['realmessage/query'],
    pagination,
    location,
    onChange (page) {
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname,
        query: {
          ...query,
          page: page.current,
          pageSize: page.pageSize,
        },
      }))
    },
    onDeleteItem (id) {
      dispatch({
        type: 'realmessage/delete',
        payload: id,
      })
    },
    onEditItem (item) {
      dispatch({
        type: 'realmessage/showModal',
        payload: {
          modalType: 'update',
          currentItem: item,
        },
      })
    },
    rowSelection: {
      selectedRowKeys,
      onChange: (keys) => {
        dispatch({
          type: 'realmessage/updateState',
          payload: {
            selectedRowKeys: keys,
          },
        })
      },
    },
  }

  // TextMessageProperties
  const textMessageProps = {
      dataSource: list,
      loading: loading.effects['realmessage/query'],
      pagination,
      location,
      isMotion,
      onChange (page) {
        const { query, pathname } = location
        dispatch(routerRedux.push({
          pathname,
          query: {
            ...query,
          page: page.current,
          pageSize: page.pageSize,
        },
      }))
      },
      onDeleteItem (id) {
        dispatch({
          type: 'realmessage/delete',
          payload: id,
        })
      },
      onEditItem (item) {
        dispatch({
          type: 'realmessage/showModal',
          payload: {
            modalType: 'update',
            currentItem: item,
          },
        })
      },
    }

  // PicMessageProperties
  const picMessageProps = {
    dataSource: list,
    loading: loading.effects['realmessage/query'],
    pagination,
    location,
    isMotion,
    onChange (page) {
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname,
        query: {
          ...query,
        page: page.current,
        pageSize: page.pageSize,
      },
    }))
    },
    onDeleteItem (id) {
      dispatch({
        type: 'realmessage/delete',
        payload: id,
      })
    },
    onEditItem (item) {
      dispatch({
        type: 'realmessage/showModal',
        payload: {
          modalType: 'update',
          currentItem: item,
        },
      })
    },
  }

  // VoiceMessageProperties
  const voiceMessageProps = {
    dataSource: list,
    loading: loading.effects['realmessage/query'],
    pagination,
    location,
    isMotion,
    onChange (page) {
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname,
        query: {
          ...query,
        page: page.current,
        pageSize: page.pageSize,
      },
    }))
    },
    onDeleteItem (id) {
      dispatch({
        type: 'realmessage/delete',
        payload: id,
      })
    },
    onEditItem (item) {
      dispatch({
        type: 'realmessage/showModal',
        payload: {
          modalType: 'update',
          currentItem: item,
        },
      })
    },
  }

  // VideoMessageProperties
  const videoMessageProperties = {
    dataSource: list,
    loading: loading.effects['realmessage/query'],
    pagination,
    location,
    isMotion,
    onChange (page) {
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname,
        query: {
          ...query,
        page: page.current,
        pageSize: page.pageSize,
      },
    }))
    },
    onDeleteItem (id) {
      dispatch({
        type: 'realmessage/delete',
        payload: id,
      })
    },
    onEditItem (item) {
      dispatch({
        type: 'realmessage/showModal',
        payload: {
          modalType: 'update',
          currentItem: item,
        },
      })
    },
  }

  const filterProps = {
    isMotion,
    filter: {
      ...location.query,
    },
    onFilterChange (value) {
      dispatch(routerRedux.push({
        pathname: location.pathname,
        query: {
          ...value,
          page: 1,
          pageSize,
        },
      }))
    },
    onSearch (fieldsValue) {
      fieldsValue.keyword.length ? dispatch(routerRedux.push({
        pathname: '/realmessage',
        query: {
          field: fieldsValue.field,
          keyword: fieldsValue.keyword,
        },
      })) : dispatch(routerRedux.push({
        pathname: '/realmessage',
      }))
    },
    onAdd () {
      dispatch({
        type: 'realmessage/showModal',
        payload: {
          modalType: 'create',
        },
      })
    },
    switchIsMotion () {
      dispatch({ type: 'realmessage/switchIsMotion' })
    },
  }

  const handleDeleteItems = () => {
    dispatch({
      type: 'realmessage/multiDelete',
      payload: {
        ids: selectedRowKeys,
      },
    })
  }
  return (
    <div className="content-inner">
      <Filter {...filterProps} />
      <TextMessage {...textMessageProps} />
    </div>
  )
}

Realmessage.propTypes = {
  realmessage: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object,
}

export default connect(({ realmessage, loading }) => ({ realmessage, loading }))(Realmessage)
